/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package locusts.lib.geom;

import java.awt.Rectangle;
import java.awt.Shape;
import java.awt.geom.AffineTransform;
import java.awt.geom.Ellipse2D;
import java.awt.geom.GeneralPath;
import java.awt.geom.PathIterator;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;

/**
 *
 * @author hamish
 */
public class MarsSymbol implements Shape, Cloneable {

    private final GeneralPath path;

    public MarsSymbol(double x, double y, double radius) {
        path = makeArrowCircle(x, y, radius);
    }

    protected MarsSymbol(MarsSymbol that) {
        this.path = (GeneralPath) that.path.clone();
    }

    private static GeneralPath makeArrowCircle(double x, double y,
            double radius) {
        final Shape circle = new Ellipse2D.Double(
                x - radius, y - radius, 2 * radius, 2 * radius);

        final GeneralPath arrow = new GeneralPath();

        final float x0 = (float) (x + radius);
        final float x1 = (float) (x + radius * 1.5);
        final float x2 = (float) (x + radius * 2);
        final float y0 = (float) (y - radius * 0.5);
        final float y1 = (float) y;
        final float y2 = (float) (y + radius * 0.5);
        arrow.moveTo(x0, y1);
        arrow.lineTo(x1, y1);
        arrow.lineTo(x1, y0);
        arrow.lineTo(x2, y1);
        arrow.lineTo(x1, y2);
        arrow.lineTo(x1, y1);
        arrow.closePath();
        arrow.append(circle, false);

        return arrow;
    }

    public Rectangle getBounds() {
        return path.getBounds();
    }

    public Rectangle2D getBounds2D() {
        return path.getBounds2D();
    }

    public boolean contains(double x, double y) {
        return path.contains(x, y);
    }

    public boolean contains(Point2D p) {
        return path.contains(p);
    }

    public boolean intersects(double x, double y, double w, double h) {
        return path.intersects(x, y, w, h);
    }

    public boolean intersects(Rectangle2D r) {
        return path.intersects(r);
    }

    public boolean contains(double x, double y, double w, double h) {
        return path.contains(x, y, w, h);
    }

    public boolean contains(Rectangle2D r) {
        return path.contains(r);
    }

    public PathIterator getPathIterator(AffineTransform at) {
        return path.getPathIterator(at);
    }

    public PathIterator getPathIterator(AffineTransform at, double flatness) {
        return path.getPathIterator(at, flatness);
    }

    @Override
    public MarsSymbol clone() {
        return new MarsSymbol(this);
    }
}
